import { readFileSync, writeFileSync } from "fs";
let publicKey = `-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApBupBxBJ6CU8potx2wi6
2AGvPlmbkwOarUvI8p4fbQpdb+WtI24LgMilO2NKcb5kRbBCiUmxmttXF7Rg6O2/
EBHKZrRCmr33JnBtzBCMsVNEPC80l4ZDLnxBEk79JVhsRCLUFxvh5Q2uBfQokVVU
2gptblYvsKoqO79JAN/o4bM718bRDeGuGq8sVZ0GgVUgAmIbMvRsWQTNz7GBN4cB
jamEqADNvWqJcFXjVjCmd9U+sfqPsLqTwSSnNAuIopCNLc0NjYCjjHuklvpHWjvC
edIXq/UuTNk+OtaIESTNIVM96llgw95b4mN9I1G1h7IZ9LeHeyU054nmJHPqxD6M
8QIDAQAB
-----END PUBLIC KEY-----`

let privateKey = `-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCkG6kHEEnoJTym
i3HbCLrYAa8+WZuTA5qtS8jynh9tCl1v5a0jbguAyKU7Y0pxvmRFsEKJSbGa21cX
tGDo7b8QEcpmtEKavfcmcG3MEIyxU0Q8LzSXhkMufEESTv0lWGxEItQXG+HlDa4F
9CiRVVTaCm1uVi+wqio7v0kA3+jhszvXxtEN4a4aryxVnQaBVSACYhsy9GxZBM3P
sYE3hwGNqYSoAM29aolwVeNWMKZ31T6x+o+wupPBJKc0C4iikI0tzQ2NgKOMe6SW
+kdaO8J50her9S5M2T461ogRJM0hUz3qWWDD3lviY30jUbWHshn0t4d7JTTnieYk
c+rEPozxAgMBAAECggEADuGvP0O74ABYcqXcikdNYj8s3BOWJwvBoAtqSo4KPYIe
HQKP49Gb227WhP8pBg2E3Ejyj66OG4PebvjdfOHqXJOwbgXUsGGfou25FzM8/uuV
GXwSYdc8CmAcKoPdMuDE2Jzr7LiLkJDgAgw1DZDWY/tkFwhbxMJ5l/dtsFWdsbHA
/sojBGpo5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');



const NodeRSA = require('node-rsa');

class RSA{
  constructor(){

  }

  /**
   * 解密
   */
  Decrypt2(encrypted, data){
    const verify = crypto.createVerify('sha256');
    // 对具体数据验证
    verify.update(data);
    verify.end();
    const result = verify.verify(publicKey, Buffer.from(encrypted,'base64'));
    return result
  }

  Decrypt(encrypted, data){
    let decryptedText = new NodeRSA(privateKey)
    decryptedText.setOptions({ encryptionScheme: 'pkcs1' })
    decryptedText = decryptedText.decrypt(encrypted, 'utf8')
    return decryptedText == data
  }
}

const rsa = new RSA()
export default rsa
